package com.nzw.controller.index;

import com.nzw.pojo.index.Banner;
import com.nzw.service.index.BannerService;
import com.nzw.vo.common.HttpResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by 18573 on 2018/9/14.
 */

@RestController
@RequestMapping("/banner")
public class BannerController {

    @Autowired
    BannerService bannerService;


    @GetMapping("/getBannerByShopId")
    public HttpResult getBannerByShopId(@RequestParam Long shopId){

        return bannerService.getBannherByShopId(shopId);
    }



    @RequestMapping(value = "/addBanner",method = RequestMethod.POST)
    public HttpResult addBanner(@RequestBody Banner banner){

        banner.setDel(false);
        return bannerService.addBanner(banner);
    }

    @RequestMapping(value = "/deleteBannerById",method = RequestMethod.POST)
    public HttpResult deleteBannerById(@RequestParam Long id){
        Banner banner = bannerService.findBannerById(id);
        banner.setDel(true);
        return bannerService.update(banner);
    }




    @GetMapping("/getBannerById")
    public HttpResult getBannerById(@RequestParam Long id){

        return new HttpResult(HttpResult.OK,bannerService.findBannerById(id));

    }
}
